package com.example.demo.controller;

import com.example.demo.pojo.Company;
import com.example.demo.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/company")
public class CompanyController {
    @Autowired
    private CompanyService companyService;

    //单条查询 /company/findById
    @GetMapping("/findById")
    public Object findById(@RequestParam("id") Integer id) {
        HashMap<String, Object> map = new HashMap();
        Company company = companyService.findById(id);
        if (company != null) {
            map.put("code", 200);
            map.put("msg", "查询成功");
            map.put("data", company);
        } else {
            map.put("code", 300);
            map.put("msg", "查询失败");
        }
        return map;
    }

    //查询所有 /company/query
    @PostMapping("/query")
    public Object query() {
        HashMap<String, Object> map = new HashMap();
        List<Company> list = companyService.query();
        if (list != null) {
            map.put("code", 200);
            map.put("msg", "查询成功");
            map.put("data", list);
        } else {
            map.put("code", 300);
            map.put("msg", "查询失败");
        }
        return map;
    }
}
